<template>
  <div id="app">
    <cover-c v-if="coverif"></cover-c>
    <marginnav></marginnav>
    <div id="headerbox">
      <title-c></title-c>
    </div>
    <div id="main">
      <keep-alive >
        <router-view> </router-view>
      </keep-alive>
    </div>
  </div>
</template>

<script>
import Bus from "@/assets/js/bus.js";
import titleC from "@/components/title/title";
import { mousemove } from "@/assets/js/Mouse";
import { getbrows } from "@/assets/js/GetBrows";
import Marginnav from "./components/common/marginnav/marginnav.vue";
import { httpGet, httpPost } from "@/network/request.js";
import { mapMutations } from "vuex";

export default {
  name: "App",
  data() {
    return {
      coverif: false,
      transitionName: "slide-left",
    };
  },
  components: {
    titleC,
    coverC: (resolve) => {
      require(["@/components/common/cover/cover"], resolve);
    },
    Marginnav,
  },
  created() {
    window.addEventListener("click", mousemove);

    this.getflie();
    this.getproject();
    this.getBrows();
    this.getgundamwall();

    //全局警告提示框
    Bus.$on("warning", (data) => {
      this.$message({
        message: data,
        showClose: true,
        type: "warning",
      });
    });
    // 全局错误提示框
    Bus.$on("error", (data) => {
      this.$message({
        message: data,
        showClose: true,
        type: "error",
      });
    });
    // 全局成功提示框
    Bus.$on("success", (data) => {
      this.$message({
        message: data,
        showClose: true,
        type: "success",
      });
    });
  },
  mounted() {
    this.loadlive2d();
    window.document.documentElement.setAttribute("theme", "dark");
  },
  methods: {
    ...mapMutations([
      "updataFile",
      "updataBrows",
      "updataProject",
      "updataGundamwallData",
    ]),
    async getflie() {
      //加载文档模块的数据
      httpGet({
        url: "/getflienav",
        params: {
          path: "/flie",
        },
      })
        .then((res) => {
          this.updataFile(res.data);
        })
        .catch((error) => {
          Bus.$emit("error", `加载文档模块数据出错:${error}`);
        });
    },
    async getproject() {
      //加载项目模块的数据
      httpGet({
        url: "/getflienav",
        params: {
          path: "/project",
        },
      })
        .then((res) => {
          this.updataProject(res.data);
        })
        .catch((error) => {
          Bus.$emit("error", `加载项目模块数据出错:${error}`);
        });
    },
    async getgundamwall() {
      //加载高达墙模块的数据
      httpGet({
        url: "/gundamwall",
      })
        .then((res) => {
          this.updataGundamwallData(res.data);
        })
        .catch((error) => {
          Bus.$emit("error", `加载高达墙数据出错:${error}`);
        });
    },
    loadlive2d() {
      //加载看板娘
      window.L2Dwidget.init({
        pluginRootPath: "live2dw/",
        pluginJsPath: "lib/",
        pluginModelPath: "live2d-widget-model-nico",
        tagMode: false,
        debug: false,
        model: {
          jsonPath:
            "../live2dw/live2d-widget-model-nico/assets/nico.model.json",
        },
        display: { position: "left", width: 200, height: 300 },
        mobile: { show: true },
        log: false,
      });
    },
    getBrows() {
      // 获取浏览器信息
      this.updataBrows({
        data: getbrows()[0],
        browsreturn: (browsinfo) => {
          let patt1 = new RegExp("firefox");
          if (patt1.test(browsinfo) == true) {
            document.querySelector("html").style.fontSize = "15px";
          }
        },
      });
    },
  },
  watch: {
    $route(to, from) {
      const fromIndex = from.meta.index;
      const toIndex = to.meta.index;
      if (toIndex > fromIndex) {
        this.transitionName = "slide-right";
      } else if (toIndex < fromIndex) {
        this.transitionName = "slide-left";
      } else {
        this.transitionName = "";
      }
    },
  },
};
</script>


<style>
@import url(./assets/css/base.css);
@import url(./assets/css/mouse.css);
@import url(./assets/css/fontcolor.css);
@import url(./assets/css/transtion.css);
</style>
